<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/list-to-detail.css" />
		<style>
			[v-cloak] {
				display: none;
			}
			
			html {
				height: 100%;
			}
			
			body {
				height: 100%;
				background-color: white;
			}
			
			.mui-icon {
				font-size: 20px;
				color: #f16456;
			}
			
			.mui-bar-nav {
				background: #f16456;
				height: 58px;
			}
			
			.mui-action-back,
			.mui-title,
			.mui-action-back:active {
				color: #FFFFFF;
			}
			
			.mui-bar .mui-title {
				margin-top: 18px;
			}
			
			.mui-bar-nav~.mui-content {
				padding-top: 58px;
			}
			
			.kr-article-content {
				background: #ffffff;
				padding-top: 5px;
			}
			
			a {
				word-break: break-word;
				width: 100%;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title" id="title">公告</h1>
		</header>
		<div class="mui-content" id="bizVue">
			<div class="kr-article-content">
				<div id="kr-article-article" class="kr-article-article" v-html="notice.content"></div>
			</div>
		</div>

		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/vue.min.js"></script>
		<script type="text/javascript" src="../js/public.js"></script>
		<script type="text/javascript">
			mui.init();

			var vm = new Vue({
				el: '#bizVue',
				data: {
					notice: {}
				},
				mounted: function() {
					mui.plusReady(function() {
						vm.loadData();
					});
				},
				methods: {
					loadData: function() {
						mui.postParam(GetNotice, null, function(result) {
							if(result.code == 0) {
								if(result.page.list.length > 0) {
									result.page.list.forEach(function(item, index) {
										if(item.id == 1) {
											// 系统公告
											item.content = replaceTag(item.content.replace(/(\r\n)|(\n)/g, '<br/>').replace(/ /g, '&nbsp;'))
											vm.notice = item;
											if(item.createTime != plus.storage.getItem("noticeCreateTime")) {
												plus.storage.setItem("noticeCheck", item.createTime);
												mui.fire(plus.webview.getWebviewById('main'), 'showNewNotice', {});
											}
										} else if(item.id == 2) {
											// 弹窗公告
											if(item.createTime != plus.storage.getItem("tipsCreateTime")) {
												mui.fire(plus.webview.getWebviewById('main'), 'showTips', {
													tips: item
												});
											}
											plus.storage.setItem("tips", item.content);
										} else if(item.id == 3) {
											// 游戏玩法
											plus.storage.setItem("howToPlay", replaceTag(item.content.replace(/(\r\n)|(\n)/g, '<br/>').replace(/ /g, '&nbsp;')));
										}

									});
								}
							} else {
								mymui(result.msg);
							}
						});
					}
				}
			});

			// 替换标签
			function replaceTag(s) {
				var index = s.indexOf("[img=");
				var link = "";
				if(index != -1) {
					link = s.substring(index + 5, s.indexOf("]", index));
					s = s.replace("[img=" + link + "]", "<img src='" + link + "'/>");
					s = replaceTag(s);
				}

				index = s.indexOf("[a=");
				if(index != -1) {
					link = s.substring(index + 3, s.indexOf("]", index));
					s = s.replace("[a=" + link + "]", "<a href=\"javascript:plus.runtime.openURL('" + link + "')\">" + link + "</a>");
					s = replaceTag(s);
				}
				return s;
			}
		</script>
	</body>

</html>